<template>
    <div>
        <el-button @click="createPathRecord">轨迹回放</el-button>
    </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getMyProjectManager } from "@/getMyProjectManager";
import { ESHumanPoi, ESPath, ESPlayer } from "esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main";
const myProjectManager = getMyProjectManager()

const createPathRecord = () => {
    const path = createPath()
    const human = createHuman()
    const player = createPlayer()
    if (path && human && player) {
        // 监听路径的位置变化
        path.currentPositionChanged.don((e) => {
            if (!path.currentPosition) return
            human.position = path.currentPosition
            if (!path.currentRotation) return
            human.rotation = path.currentRotation
        })
        // 开始播放
        player.playing = true
    }
}

// 创建path路径
const createPath = () => {
    const path = myProjectManager.createSceneObject(ESPath)
    if (!path) return
    path.strokeWidth = 0.5
    path.strokeColor = [0, 1, 1, 1]
    // 点位信息
    path.points = [
        [
            114.04235478194634,
            38.067294247536054,
            304.2274413612017
        ],
        [
            114.04236074530735,
            38.067347794847564,
            304.22744772074884
        ],
        [
            114.04258678366223,
            38.06733138475052,
            304.22737530595697
        ],
        [
            114.04278403153037,
            38.06731579982655,
            304.22736804444776
        ],
        [
            114.042775386445,
            38.06725849771533,
            304.22742632810974
        ],
        [
            114.042775386445,
            38.06725849771533,
            304.22742632810974
        ]
    ]
    // 时间序列（时间戳）
    path.timeStamps = [
        1734395959857,
        1734395960834,
        1734395985706,
        1734396003060,
        1734396009477,
        1734396009477
    ]
    return path
}
// 创建人员
const createHuman = () => {
    const human = myProjectManager.createSceneObject(ESHumanPoi)
    if (!human) return
    human.position = [114.0426606231189, 38.067354306556624, 286.02736510783143]
    human.name = "轨迹回放"
    human.mode = "suitMan"//["陌生人", "stranger"], ["男士", 'suitMan'], ["女士", 'suitWoman']
    human.animation = "walking"
    human.poiMode = 'ManNormal' //['Stranger', 'Stranger'], ['ManNormal', 'ManNormal'],['ManAbnormal', 'ManAbnormal'],['WomanNormal', 'WomanNormal'],['WomanAbnormal', 'WomanAbnormal'],
    return human
}
// 创建播放器
const createPlayer = () => {
    const player = myProjectManager.createSceneObject(ESPlayer)
    if (!player) return
    // 设置ESPlayer播放器
    player.startTime = 1734395959857
    player.stopTime = 1734396009477
    player.loop = true
    player.currentTimeChanged.don((e) => {
        if (e == player.stopTime) {
            alert('播放结束')
        }
    })
    return player
}


</script>
<style scoped></style>
